package com.ruoyi.web.controller.stock;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.stock.domain.vo.WarehouseOutInfoNumberVo;
import com.ruoyi.stock.service.WarehouseOutStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: YwaiX
 * @Version: 1.0
 * @Date: Created in 2024-10-31 19:06:07
 * @Description:
 */

@RestController
@RequestMapping("/stock/OutStock")
public class WarehouseOutStockController extends BaseController {

    @Autowired
    private WarehouseOutStockService warehouseOutStockService;

    /**
     * 查询出库详情信息
     * @param warehouseOutInfoId
     * @param goodsType
     * @return
     */
    @PreAuthorize("@ss.hasAnyPermi('stock:out:outStock')")
    @GetMapping("list")
    public AjaxResult list(Integer warehouseOutInfoId,Integer goodsType){
        return success(warehouseOutStockService.list(warehouseOutInfoId, goodsType));
    }

    /**
     * 库存列表
     * @param goodsNo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('stock:out:stockList')")
    @GetMapping("stockList")
    public AjaxResult stockList(String goodsNo,String sourceNo){
        return success(warehouseOutStockService.stockList(goodsNo,sourceNo));
    }

    /**
     * 添加出库记录
     * @param warehouseOutInfoNumberVo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('stock:out:updateStock')")
    @PostMapping("updateStock")
    public AjaxResult outStock(@RequestBody WarehouseOutInfoNumberVo warehouseOutInfoNumberVo){
        return toAjax(warehouseOutStockService.outStock(warehouseOutInfoNumberVo));
    }

    /**
     * 修改出库单状态
     * @param warehouseOutId
     * @param goodsType
     * @param sourceNo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('stock:out:updateWarehouseStatus')")
    @GetMapping("updateWarehouseStatus")
    public AjaxResult updateWarehouseStatus(Integer warehouseOutId,Integer goodsType,String sourceNo){
        return toAjax(warehouseOutStockService.updateWarehouseStatus(warehouseOutId,goodsType,sourceNo,getLoginUser().getUserId(), DateUtils.getNowDate()));
    }
}
